package com.wshl.aijiuunion.view.adapter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.wshl.aijiuunion.NetUrl;
import com.wshl.aijiuunion.R;
import com.wshl.aijiuunion.controller.activity.StoreDetailActivity;
import com.wshl.aijiuunion.view.bean.FujinStoreBean;
import com.wshl.aijiuunion.utils.GlideUtils;
import com.wshl.aijiuunion.view.widget.RoundCornerImageView;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

import cn.bingoogolapple.baseadapter.BGAOnRVItemClickListener;
import cn.bingoogolapple.baseadapter.BGARecyclerViewAdapter;
import cn.bingoogolapple.baseadapter.BGAViewHolderHelper;

/**
 * Created buy 风凊扬 on 2019/10/24 0024
 */
public class FujinStoreAdapter extends BGARecyclerViewAdapter<FujinStoreBean> implements BGAOnRVItemClickListener {

    public FujinStoreAdapter(RecyclerView recyclerView) {
        super(recyclerView, R.layout.item_fujin_store);
        setOnRVItemClickListener(this);
    }

    @Override
    protected void fillData(BGAViewHolderHelper helper, int position, FujinStoreBean model) {


        RoundCornerImageView imageView = (RoundCornerImageView) helper.getImageView(R.id.img_fujin);
        helper.setText(R.id.tv_mendian, model.getName());
        helper.setText(R.id.tv_mendian_address, model.getAddress());
        helper.setText(R.id.tv_mendian_tel, model.getPhone());
        helper.setText(R.id.tv_distance, model.getDistance() + "Km");
        GlideUtils.loadImage(mContext, NetUrl.IMG + model.getThumb(), imageView);
    }

    @Override
    public void onRVItemClick(ViewGroup parent, View itemView, int position) {

        FujinStoreBean fujinStoreBean = getData().get(position);
        String name = fujinStoreBean.getName();
        ArrayList<String> images = (ArrayList<String>) fujinStoreBean.getImages();
        String address = fujinStoreBean.getAddress();
        String phone = fujinStoreBean.getPhone();
        String thumb = fujinStoreBean.getThumb();
        String lat = fujinStoreBean.getLat();
        String lng = fujinStoreBean.getLng();
        double distance = fujinStoreBean.getDistance();
        String open_time = fujinStoreBean.getOpen_time();

        Intent intent = new Intent(mContext, StoreDetailActivity.class);
        if (images != null && images.size() > 0) {
            StringBuilder stringBuilder = new StringBuilder();

            for (String image : images) {

                stringBuilder.append(image).append(";");
            }

            intent.putExtra("images", stringBuilder.toString());
        }

        intent.putExtra("name", name);
        intent.putExtra("address", address);
        intent.putExtra("phone", phone);
        intent.putExtra("thumb", thumb);
        intent.putExtra("lat", lat);
        intent.putExtra("lng", lng);
        intent.putExtra("distance", distance);
        intent.putExtra("opentime", open_time);
        mContext.startActivity(intent);

    }
}
